package com.warmheart.base.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.warmheart.base.page.BasePage;
import com.warmheart.core.co.base.BaseCoBuilder;
import com.warmheart.core.co.model.OrderByModel;
import com.warmheart.core.co.model.RelationModel;
import com.warmheart.core.combine.model.CombineModel;
import com.warmheart.core.combine.model.JoinModel;
import com.warmheart.core.cors.builder.CoRsBuilder;
import com.warmheart.core.enums.DELETED;
import com.warmheart.core.ignore.IgnoreFilter;
import com.warmheart.core.rs.base.BaseRsBuilder;
import com.warmheart.core.rs.enums.SmTypeEnum;
import com.warmheart.core.rs.model.DistinctModel;
import com.warmheart.core.rs.model.SelectedModel;

public abstract class BaseEntity<E extends BaseCoBuilder<?, ?>, R extends BaseRsBuilder<?, ?>> extends BasePage
        implements CoRsBuilder<E, R> {

    private static final long serialVersionUID = 1L;
    
    /**
     * 联合模型
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private CombineModel combineModel;

    /**
     * 联合关系模型
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private JoinModel joinModel;

    /**
     * 关系模型
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private List<RelationModel> relationModelList = new ArrayList<RelationModel>();

    /**
     * 排序模型
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private List<OrderByModel> orderByModelList = new ArrayList<OrderByModel>();

    /**
     * 过滤重复模型
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private DistinctModel distinctModel;

    /**
     * 查询模型
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private List<SelectedModel> selectedModelList;
    
    @Override
    public CombineModel getCombineModel() {
        if (combineModel == null) {
            combineModel = new CombineModel();
        }
        return combineModel;
    }
    
    @Override
    public JoinModel getJoinModel() {
        if (joinModel == null) {
            joinModel = new JoinModel();
        }
        return joinModel;
    }

    @Override
    public List<RelationModel> getRelationModelList() {
        if (relationModelList == null) {
            relationModelList = new ArrayList<RelationModel>();
        }
        return relationModelList;
    }

    @Override
    public List<OrderByModel> getOrderByModelList() {
        if (orderByModelList == null) {
            orderByModelList = new ArrayList<OrderByModel>();
        }
        return orderByModelList;
    }

    @Override
    public DistinctModel getDistinctModel() {
        if (distinctModel == null) {
            distinctModel = new DistinctModel(true, SmTypeEnum.MULTIPLE);
        }
        return distinctModel;
    }

    @Override
    public List<SelectedModel> getSelectedModelList() {
        if (selectedModelList == null) {
            selectedModelList = new ArrayList<SelectedModel>();
        }
        return selectedModelList;
    }

    /**
     * 主键
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer id;

    /**
     * 创建人
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private Integer createBy;

    /**
     * 创建日期
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Date cstCreate;

    /**
     * 更新人
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private Integer updateBy;

    /**
     * 更新时间
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Date cstModify;

    /**
     * 备注
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String remarks;

    /**
     * 删除标志（01：正常，02：已删除）
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private String delFlag;

    /**
     * 自定义数据（SQL临时传参专用，不要用作其它用途，避免数据混乱）
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private Map<String, Object> map = new HashMap<String, Object>();
    
    /**
     * 自定义返回数据
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private Map<String, Object> rsMap = new HashMap<String, Object>();

    /**
     * 临时数据（临时存储数据专用）
     */
    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    private Map<String, Object> temp = new HashMap<String, Object>();

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Integer createBy) {
        this.createBy = createBy;
    }

    public Date getCstCreate() {
        return cstCreate;
    }

    public void setCstCreate(Date cstCreate) {
        this.cstCreate = cstCreate;
    }

    public Integer getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(Integer updateBy) {
        this.updateBy = updateBy;
    }

    public Date getCstModify() {
        return cstModify;
    }

    public void setCstModify(Date cstModify) {
        this.cstModify = cstModify;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    public String getNomalDelFlag() {
        return DELETED.DELETED_NO.getValue();
    }

    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreFilter.class)
    public String getDeletedFlag() {
        return DELETED.DELETED_YES.getValue();
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }
    
    public Map<String, Object> getRsMap() {
        return rsMap;
    }

    public void setRsMap(Map<String, Object> rsMap) {
        this.rsMap = rsMap;
    }

    public Map<String, Object> getTemp() {
        return temp;
    }

    public void setTemp(Map<String, Object> temp) {
        this.temp = temp;
    }
}